﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YTSK.cSK
{
    class cSKSet
    {

        /// <summary>
        /// 获取最大的开票限额
        /// </summary>
        /// <param name="cbilltype"></param>
        /// <returns></returns>
        public static decimal GetMaxMoney(FpType cbilltype)
        {
            decimal maxmoney = 0;
            switch (cbilltype)
            {
                case FpType.纸质专用发票:
                    maxmoney = cSK.cSKSet.loadsave(SkConfig.专用发票限额).ObjToDecimal();
                    if (maxmoney == 0) { maxmoney = 116000; }
                    break;
                case FpType.纸质普通发票:
                    maxmoney = cSK.cSKSet.loadsave(SkConfig.普通发票限额).ObjToDecimal();
                    if (maxmoney == 0)
                    {
                        maxmoney = 11600;
                    }
                    break;
                case FpType.电子专用发票:
                    maxmoney = cSK.cSKSet.loadsave(SkConfig.专用发票限额).ObjToDecimal();
                    if (maxmoney == 0) { maxmoney = 116000; }
                    break;
                case FpType.电子普通发票:
                default:
                    maxmoney = cSK.cSKSet.loadsave(SkConfig.电子发票限额).ObjToDecimal();
                    if (maxmoney == 0)
                    {
                        maxmoney = 11600;
                    }
                    break;
            }
            if (maxmoney == 0) { maxmoney = 100000; }
            return maxmoney;
        }


        #region 保存税控设置
        /// <summary>
        /// 保存税控设置
        /// </summary>
        /// <param name="codetype"></param>
        /// <param name="value"></param>
        public static void updatecode(SkConfig codetype, string value)
        {
            var s = Enum.GetName(typeof(SkConfig), codetype);
            Common.HandleRegistry.saveKey(s, value, "SK");
        }
        #endregion

        #region 获取税控设置
        /// <summary>
        /// 获取税控设置
        /// </summary>
        /// <param name="codetype"></param>
        /// <returns></returns>
        public static string loadsave(SkConfig codetype)
        {
            var s = Enum.GetName(typeof(SkConfig), codetype);
            var val = Common.HandleRegistry.readKey(s, "SK");
            switch (codetype)
            {
                case SkConfig.延时设置:
                    if (val.ObjToInt() == 0) { val = 500.ToString(); }
                    break;
                case SkConfig.专用发票限额:
                    if (val.ObjToInt() == 0) { val = 116000.ToString(); }
                    break;
                case SkConfig.普通发票限额:
                case SkConfig.电子发票限额:
                    if (val.ObjToInt() == 0)
                    {
                        switch(ServerConfig._company)
                        {
                            case Company.上海Iteng:
                                val = 116000.ToString();
                                break;
                            default:
                                val = "11600";
                                break;
                        }                        
                    }
                    break;
            }
            if (val.ObjToString().Length > 0) { return val; }
            return "";
        }
        #endregion
    }
}
